<template>
	<view>
		<view class="pickerBox">
			<view :class="typeNum == null ? 'pickerClass typeBor':'pickerClass typeBorCC'" @click="ontypeNum(null)">
				<view class="picker_border">全部</view>
			</view>
			<view class="flex-1"></view>
			<view :class="typeNum == 7 ? 'pickerClass typeBor':'pickerClass typeBorCC'" @click="ontypeNum(7)">
				<view class="picker_border">近7次</view>
			</view>
			<view :class="typeNum == 30 ? 'pickerClass typeBor ml20':'pickerClass ml20 typeBorCC'"
				@click="ontypeNum(30)">
				<view class="picker_border">近30次</view>
			</view>
		</view>
		<!-- <view class="m-0-30">
			<uni-data-select v-model="statisType" :localdata="selectFange" @change="rangeChange"></uni-data-select>
		</view> -->
		<mrsongCharts type='line' title="" align='left' :chartsData="chartsData2" :config="config2" />

		<mrsongCharts type='line' title="" align='left' :chartsData="chartsData" :config="config" />
		<!-- <view class="poFibutt">
			<button open-type="share">
				<view class="icon-share1 icon iconfont"></view>
			</button>
		</view> -->
	</view>

</template>

<script>
	import configlist from '@/env/config.js';
	import mrsongCharts from '@/pagesLive/components/mrsong-charts/components/mrsong-charts/mrsong-charts.vue';
	export default {
		components: {
			mrsongCharts
		},
		data() {
			return {
				chartsData: {
					categories: [], //x轴
					series: [{
						data: [],
						name: '共同富裕趋势图'
					}],
				},
				config: {
					color: ["#FF6666"],
				},
				chartsData2: {
					categories: [], //x轴
					series: [{
						data: [],
						name: '英雄榜趋势图'
					}],
				},
				config2: {
					color: ["#6699FF"],
				},
				selectFange: [{
						value: 0,
						text: "共同富裕趋势图"
					},
					{
						value: 1,
						text: "英雄榜趋势图",
					},
				],
				statisType: 0,
				typeNum: null,
			}
		},
		onLoad(option) {

		},
		onReady() {
			if (configlist.appId == 10002) {
				uni.setNavigationBarTitle({
					title: '共同富裕及英雄榜奖金池'
				});
			}
		},
		onShow() {
			this.getStatistics();
			this.getHeroStatistics()
		},
		// created() {
		// 	this.getStatistics();
		// 	this.getHeroStatistics()
		// },
		methods: {
			rangeChange(e) {
				this.typeNum = null;
				e == 1 ? this.getStatistics() : this.getHeroStatistics();
			},
			//英雄
			getHeroStatistics() {
				let that = this
				uni.showLoading({
					title: '加载中'
				})
				that._get('user/commonProsperity/heroRanking/statistics', {
					num: that.typeNum
				}, function(res) {
					that.dataTreating(res.data.xlist, res.data.ylist, 0);
					uni.hideLoading();
				})
			},
			//共同富裕
			getStatistics() {
				let that = this
				uni.showLoading({
					title: '加载中'
				})
				that._get('user/commonProsperity/statistics', {
					num: that.typeNum
				}, function(res) {
					that.dataTreating(res.data.xlist, res.data.ylist, 1);
					uni.hideLoading()
				})
			},
			//数据处理
			dataTreating(xlist, ylist, type) {
				if (type == 0) {
					this.chartsData.categories = xlist.map((item, index) => {
						return `第${index+1}周`;
					});
					this.chartsData.series[0].data = ylist
				} else {
					this.chartsData2.categories = xlist.map((item, index) => {
						return `第${index+1}周`;
					});
					this.chartsData2.series[0].data = ylist
				}

			},
			ontypeNum(e) {
				this.typeNum = e;
				this.getStatistics();
				this.getHeroStatistics();
			},


		}

	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #FFF;
	}

	.pickerBox {
		font-family: PingFang SC;
		margin: 60rpx 30rpx 20rpx 30rpx;
		display: flex;
		align-items: center;
		font-weight: 400;
		font-size: 30rpx;
		color: #333333;

		text {
			margin: 0 20rpx;
			font-weight: bold;
			font-size: 32rpx;
		}


		.picker_border {
			width: 120rpx;
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}

	.poFibutt {
		position: fixed;
		width: 100%;
		bottom: 10%;
		left: 75%;

		button {
			width: 118rpx;
			height: 118rpx;
			background: linear-gradient(150deg, #02C46E, #14854D);
			border-radius: 50%;
		}

		.iconfont {
			font-size: 45rpx;
			color: white;
		}

	}

	.typeBor {
		border: 1rpx solid #01a159;
		color: #01a159;
		border-radius: 10rpx;
	}

	.typeBorCC {
		border: 1rpx solid #CCC;
		border-radius: 10rpx;
	}
</style>